package wk.demo.bean;

import android.app.Application;
import android.content.Context;

import com.danikula.videocache.HttpProxyCacheServer;
import com.tencent.mmkv.MMKV;

import org.litepal.LitePal;

import wk.demo.activities.FileExplorerActivity;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        MMKV.initialize(this);
        LitePal.initialize(this);

        MyAppLifecycleHandler lifecycleHandler =
                new MyAppLifecycleHandler( FileExplorerActivity.class.getSimpleName() ) ;

        unregisterActivityLifecycleCallbacks(lifecycleHandler);
        registerActivityLifecycleCallbacks(  lifecycleHandler ) ;
    }

    private HttpProxyCacheServer proxy;
    public static HttpProxyCacheServer getProxy(Context context) {
        MyApplication app = (MyApplication) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy(context)) : app.proxy;
    }

    private HttpProxyCacheServer newProxy(Context context) {
        return new HttpProxyCacheServer.Builder(context)
                .fileNameGenerator(new MyFileNameGenerator()) // 缓存文件名字
                .maxCacheSize(1024 * 1024 * 1024)       // 1 Gb for cache
                .build();
    }




}
